#ifndef MX25L1606E_H
#define MX25L1606E_H
#include "main.h"

#define FLASH_BUSY_TIMEOUT  200

#define FLASH_PAGE_SIZE     256

#define RDID_CMD  0X9F
#define RDSD_CMD  0X05
#define WRSR_CMD  0x01
#define REMS_CMD  0X90
#define DP_CMD    0XB9
#define RDP_CMD   0XAB
#define RES_CMD   0XAB
#define PP_CMD    0X02
#define WREN_CMD  0X06
#define WRDI_CMD  0X04
#define CE_CMD    0XC7
#define BE_CMD    0X52
#define SE_CMD    0x20
#define READ_CMD  0X03
#define FREAD_CMD 0X0B
#define DREAD_CMD 0X3B


#define Block0_st_addr 0x000000
#define Block1_st_addr 0x010000
#define Block2_st_addr 0x020000
#define Block3_st_addr 0x030000
#define Block4_st_addr 0x040000
#define Block5_st_addr 0x050000
#define Block6_st_addr 0x060000
#define Block7_st_addr 0x070000
#define Block8_st_addr 0x080000
#define Block9_st_addr 0x090000
#define Block10_st_addr 0x0A0000
#define Block11_st_addr 0x0B0000
#define Block12_st_addr 0x0C0000
#define Block13_st_addr 0x0D0000
#define Block14_st_addr 0x0E0000
#define Block15_st_addr 0x0F0000
#define Block16_st_addr 0x100000
#define Block17_st_addr 0x110000
#define Block18_st_addr 0x120000
#define Block19_st_addr 0x130000
#define Block20_st_addr 0x140000
#define Block21_st_addr 0x150000
#define Block22_st_addr 0x160000
#define Block23_st_addr 0x170000
#define Block24_st_addr 0x180000
#define Block25_st_addr 0x190000
#define Block26_st_addr 0x1A0000
#define Block27_st_addr 0x1B0000
#define Block28_st_addr 0x1C0000
#define Block29_st_addr 0x1D0000
#define Block30_st_addr 0x1E0000
#define Block31_st_addr 0x1F0000

typedef struct
{
    u8 ManufacturerID;
    u8 DeviceID[2];
}flashInfoTypedef;

extern void MX25L1606E_Flash_Init(void);
extern void FlashPage_Read(u8 *ptr,u32 pageAddr,u32 pageSize);
extern void FlashPage_Write(u8 *ptr,u32 pageAddr,u32 pageSize);
extern void FlashSector_Erase(u32 sectorAddr);
extern void FlashBlock_Erase(u8 blockAddr);
extern void FlashChip_Erase(void);
extern void FlashRead(u8 *ptr,u32 addr,u32 len);
extern void SPI_FLASH_BufferWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite);
#endif
